from PIL import Image
from io import BytesIO

def load_image(data: bytes) -> Image.Image:
    return Image.open(BytesIO(data))

def save_image(img: Image.Image) -> bytes:
    buf = BytesIO()
    img.save(buf, format="PNG")
    buf.seek(0)
    return buf.getvalue()